import numpy as np
import platgo as pg


class Sphere(pg.Problem):

    def __init__(self, D: int = 20) -> None:
        self.name = 'Sphere'
        self.type = '111'
        self.M = 1
        self.D = D
        lb = [-5] * self.D
        ub = [5] * self.D
        self.borders = np.array([lb, ub])
        super().__init__()

    def cal_obj(self, pop: pg.Population) -> None:
        x = pop.decs
        pop.objv = np.array([np.sum(np.square(abs(x)), 1)]).T

    def get_optimal(self) -> np.ndarray:
        return np.array([[0]])